package com.qinhailin.portal.dbm.service;

import com.jfinal.aop.Inject;
import com.jfinal.plugin.activerecord.Record;
import com.qinhailin.common.vo.Grid;
import com.qinhailin.portal.dbm.model.CTCustomer;

/** 2019-11-23 21:28:45 批量生成 harrydeep@wardyan.top **/
public class CTCustomerServiceImpl extends MasterServiceImpl<CTCustomer>{

	@Inject
	DTSystemdataServiceImpl systemdataService;
	
	public CTCustomerServiceImpl() {super(CTCustomer.dao);}



	public Grid page(int pageNumber, int pageSize, Record record) {
		Record rd = new Record();
		rd.set("xName LIKE", record.getStr("xName"));
		String sql="SELECT	m.*, STUFF((SELECT ',' + CAST(n.rQuery_ID AS NVARCHAR(30)) FROM dbo.dt_schedule AS n WHERE n.rCust_ID = m.sID AND n.xStatus IN (0, 1) FOR XML PATH('')), 1, 1, '') AS xSchedule FROM dbo.ct_customer AS m WHERE 1 = 1";
		
		return queryForList(sql,pageNumber, pageSize, rd, null);
	}
	
	public Integer heartbeatInterval(Integer rCustID) {
		Integer rs = null;
		CTCustomer c = this.findByID(rCustID);
		if(c != null) {
			rs = c.getXHeartbeatInterval();
		}
		if(rs == null || rs <= 0) {
			rs = systemdataService.heartbeatInterval();
		}
		return rs;
	}
}
